<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增文章草稿')"/>
    <th:block th:include="include :: summernote-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-draft-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">分类ID：</label>
            <div class="col-sm-8">
                <input class="form-control" name="categoryId" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">分类名称：</label>
            <div class="col-sm-8">
                <input class="form-control" name="categoryName" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">平台：</label>
            <div class="col-sm-8">
                <select class="form-control m-b" name="platform"
                        th:with="type=${@dict.getType('biz_account_platform')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <input class="form-control" name="title" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">繁体标题：</label>
            <div class="col-sm-8">
                <input class="form-control" name="tTitle" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <select class="form-control m-b" name="dataState"
                        th:with="type=${@dict.getType('biz_article_data_state')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">wp文章发布后的id：</label>
            <div class="col-sm-8">
                <input class="form-control" name="wpPostId" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">作者：</label>
            <div class="col-sm-8">
                <input class="form-control" name="author" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">繁体作者：</label>
            <div class="col-sm-8">
                <input class="form-control" name="tAuthor" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">url hash：</label>
            <div class="col-sm-8">
                <input class="form-control" name="urlHash" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">文章链接：</label>
            <div class="col-sm-8">
                <textarea class="form-control" name="url" required></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">正文：</label>
            <div class="col-sm-8">
                <input class="form-control" name="content" type="hidden">
                <div class="summernote" id="content"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">繁体正文：</label>
            <div class="col-sm-8">
                <input class="form-control" name="tContent" type="hidden">
                <div class="summernote" id="tContent"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文章封面图片：</label>
            <div class="col-sm-8">
                <input class="form-control" name="coverImage" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否原创，0否，1是：</label>
            <div class="col-sm-8">
                <input class="form-control" name="original" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-8">
                <textarea class="form-control" name="description"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">繁体描述：</label>
            <div class="col-sm-8">
                <textarea class="form-control" name="tDescription"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">关键字：</label>
            <div class="col-sm-8">
                <input class="form-control" name="keywords" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">繁体关键字：</label>
            <div class="col-sm-8">
                <input class="form-control" name="tKeywords" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: summernote-js"/>
<script th:inline="javascript">
    var prefix = ctx + "cms/draft"
    $("#form-draft-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-draft-add').serialize());
        }
    }

    $(function () {
        $('.summernote').summernote({
            lang: 'zh-CN',
            callbacks: {
                onChange: function (contents, $edittable) {
                    $("input[name='" + this.id + "']").val(contents);
                },
                onImageUpload: function (files) {
                    var obj = this;
                    var data = new FormData();
                    data.append("file", files[0]);
                    $.ajax({
                        type: "post",
                        url: ctx + "common/upload",
                        data: data,
                        cache: false,
                        contentType: false,
                        processData: false,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == web_status.SUCCESS) {
                                $('#' + obj.id).summernote('insertImage', result.url);
                            } else {
                                $.modal.alertError(result.msg);
                            }
                        },
                        error: function (error) {
                            $.modal.alertWarning("图片上传失败。");
                        }
                    });
                }
            }
        });
    });
</script>
</body>
</html>